package com.yj.web.controller.asset;


import com.yj.asset.domain.AssetImage;
import com.yj.asset.service.AssetImageService;
import com.yj.common.core.controller.BaseController;
import com.yj.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * <p>
 * 内容图片 前端控制器
 * </p>
 *
 * @author yj
 * @since 2021-09-27
 */
@RestController
@Api("中部内容图片接口")
@RequestMapping("/asset/assetImage")
public class AssetImageController extends BaseController {

    private final AssetImageService assetImageService;

    @Autowired
    public AssetImageController(AssetImageService assetImageService) {
        this.assetImageService = assetImageService;
    }

    @GetMapping("/getImageList")
    @ApiOperation("查询")
    @PreAuthorize("@ss.hasPermi('asset:Image:query')")
    public AjaxResult getImageList(
            @ApiParam(required = true, name = "code", value = "位置编码")@RequestParam("code") String code,
            @ApiParam(required = false, name = "id", value = "主键")@RequestParam(value = "id" ,required=false) String id
    ){
        return assetImageService.getImageList(code,id);
    }

    @PostMapping("/addAssetImage")
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('asset:Image:add')")
    public AjaxResult addAssetImage(@RequestBody AssetImage  assetImage) throws IOException {
        return assetImageService.addAssetImage(assetImage);
    }

    @PostMapping("/uqAssetImg")
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('asset:Image:uq')")
    public AjaxResult uqAssetImg(@RequestBody AssetImage  assetImage) throws IOException {
        return assetImageService.uqAssetImg(assetImage);
    }

    @PostMapping("/deleteAssImg")
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('asset:Image:de')")
    public AjaxResult deleteAssImg(@RequestBody AssetImage  assetImage){
        return assetImageService.deleteAssImg(assetImage);
    }
}

